<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="object">
    <doc>
      <field name="medium">Electronic</field>
      <field name="location">Online</field>
      <xsl:apply-templates></xsl:apply-templates>
    </doc>
  </xsl:template>
  
  <!-- Suppress all unmatched text/attributes -->
  <xsl:template match="text()|@*"/>
  
  <xsl:template match="identifier[@type='issn']">
    <field name="identifier">URN:ISSN:<xsl:value-of select="."/></field>
    <field name="issn"><xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="identifier[@type='isbn']">
    <field name="identifier">URN:ISBN:<xsl:value-of select="."/></field>
    <field name="isbn"><xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="identifier[@type='lccn']">
    <field name="identifier">URN:LCCN:<xsl:value-of select="."/></field>
    <field name="lccn"><xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="identifier[@type='object_id']">
    <field name="identifier">URN:SFXObject:<xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="identifier[@type='object_portfolio']">
    <field name="identifier">URN:SFXObjectPortfolio:<xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="identifier[@type='target']">
    <field name="identifier">URN:SFXTarget:<xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="identifier[@type='target_service']">
    <field name="identifier">URN:SFXTargetService:<xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="identifier[@type='object_portfolio']">
    <field name="identifier">URN:SFXObjectPortfolio:<xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="title">
    <xsl:choose>
      <xsl:when test="string-length(@type)"><field name="alternateTitle"><xsl:value-of select="."/></field></xsl:when>
      <xsl:otherwise><field name="title"><xsl:value-of select="."/></field></xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="target_public_name">
    <field name="source"><xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="threshold">
    <xsl:if test="not(string-length(@type))">
      <field name="description"><xsl:value-of select="."/></field>
    </xsl:if> 
  </xsl:template>
  <xsl:template match="category">
    <field name="subject"><xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="local_attribute">
    <field name="description"><xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="publisher">
    <field name="publisher"><xsl:value-of select="."/>, <xsl:value-of select="../publisher_place"/></field>
  </xsl:template>
  <xsl:template match="date[@type='publication']">
    <field name="datePublished"><xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="object_type">
    <field name="type"><xsl:value-of select="."/></field>
    <field name="format"><xsl:value-of select="."/></field>
  </xsl:template>
  <xsl:template match="language">
    <field name="language"><xsl:value-of select="."/></field>
  </xsl:template>
</xsl:stylesheet>  

